<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>日志管理</title>
	<link rel="stylesheet" href="/static/css/layui.css" />
	<link rel="stylesheet" href="/static/css/common.css" />
</head>

<body class="container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">模块</label>
						<div class="layui-input-inline">
							<input type="text" name="l.log" placeholder="" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-inline">
						<label class="layui-form-label">操作人</label>
						<div class="layui-input-inline">
							<input type="text" name="u.username" placeholder="" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-inline">
						<button class="layui-btn layui-btn-md layui-btn-primary" lay-submit lay-filter="user-query">
							<i class="layui-icon layui-icon-search"></i>
							查询
						</button>
						<button type="reset" class="layui-btn layui-btn-md" lay-filter="user-reset" lay-submit>
							<i class="layui-icon layui-icon-refresh"></i>
							重置
						</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="user-table" lay-filter="user-table"></table>
		</div>
	</div>

	<script type="text/html" id="user-toolbar">
		    
		</script>

	


	<script type="text/html" id="user-loginTime">
			{{layui.util.toDateString(d.login_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
		</script>

	<script src="/static/js/layui.js"></script>
	<script>
		layui.extend({
			api: '{/}/static/js/api' // 开头特定符 {/} 即代表采用单独路径
		});
		layui.use(['api'], function () {
			let api = layui.api;
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let common = layui.common;

			let MODULE_PATH = "./";

			let cols = [
				[{
					title: '模块',
					field: 'log',
					align: 'center'
				},
				{
					title: '请求方式',
					field: 'method',
					align: 'center'
				},
				{
					title: '接口',
					field: 'url',
					align: 'center'
				},
				{
					title: '浏览器',
					field: 'agent',
					align: 'center'
				},
				{
					title: '操作时间',
					field: 'addtime',
					templet: '#log-createTime',
					align: 'center'
				},
				{
					title: '操作人',
					field: 'username',
					align: 'center'
				},
				{
					title: '访问数据',
					field: 'data',
					align: 'center',
					width: 150
				}
				]
			]
			table.render({
				elem: '#user-table',
				url: api.apiUrl + 'logs/list',
				headers: api.getHeader(),
				parseData: function (res) {
					//console.log(res)
					return {
						"code": res.code, //解析接口状态
						"msg": res.message, //解析提示文本
						"count": res.data.count, //解析数据长度
						"data": res.data.list //解析数据列表
					};
				},
				page: true,
				cols: cols,
				skin: 'line',

				toolbar: '#user-toolbar',
				defaultToolbar: [{
					title: '刷新',
					layEvent: 'refresh',
					icon: 'layui-icon-refresh',
				}, 'filter', 'print', 'exports']
			});

			

			table.on('toolbar(user-table)', function (obj) {
				if (obj.event === 'refresh') {
					window.refresh();
				} else if (obj.event === 'batchRemove') {
					window.batchRemove(obj);
				}
			});
			// 监听搜索操作

			form.on('submit(user-query)', function (data) {
				table.reload('user-table', {
					where: {
						param: $('form').serialize()
					},
					page: {
						curr: 1
					}
				})
				return false;
			});
			form.on('submit(user-reset)', function (data) {
				table.reload('user-table', {
					where: {
						param: ''
					},
					page: {
						curr: 1
					}
				});
				return false;
			})
			
			

			


			window.refresh = function (param) {
				table.reload('user-table');
			}
		})
	</script>
</body>

</html>